package edu.csl.study.shardingsphere.health.service.impl;

import edu.csl.study.shardingsphere.health.entity.EncryptUser;
import edu.csl.study.shardingsphere.health.mapper.EncryptUserMapper;
import edu.csl.study.shardingsphere.health.service.IEncryptUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 自动生成代码
 * @since 2022-05-21
 */
@Service
public class EncryptUserServiceImpl extends ServiceImpl<EncryptUserMapper, EncryptUser> implements IEncryptUserService {

    @Override
    public void processEncryptUsers() throws SQLException {
        insertEncryptUsers();
    }

    private List<Long> insertEncryptUsers() throws SQLException {
        List<Long> result = new ArrayList<>(10);
        for (Long i = 1L; i <= 10; i++) {
            EncryptUser encryptUser = new EncryptUser();
            encryptUser.setUserId(i);
            encryptUser.setUserName("test_" + i);
            encryptUser.setPwd("pwd" + i);
            baseMapper.insert(encryptUser);
            result.add(encryptUser.getUserId());
        }

        return result;
    }

    @Override
    public List<EncryptUser> getEncryptUsers() throws SQLException {
        return baseMapper.selectList(null);
    }

    @Override
    public void deleteAll() {
        baseMapper.delete(null);
    }

}
